package lms.utils;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @description: 输入正则表达式验证
 * @author: Grape_Pip
 * @time: 2021/04/20 16:11
 */
public class VerificationInput implements Serializable {
    private static Pattern pTel = Pattern.compile("1[0-9]{10}");
    private static Pattern pDate = Pattern.compile("\\d{4}-(0?[1-9]|1[0-2])-(0?[1-9]|[1,2][0-9]|3[0-1])");
    private static Pattern p = Pattern.compile("[0-9]*");
    /**
     * 判断输入的正则方法
     */
//    验证手机号
    public static boolean isMobileNO(String mobiles) {
        boolean flag = false;
        try {
            Matcher m = pTel.matcher(mobiles);
            flag = m.matches();

        } catch (Exception e) {
            flag = false;
        }
        return flag;
    }

    //    验证日期
    public static boolean isDate(String date) {
        boolean flag = false;
        try {

            Matcher m = pDate.matcher(date);
            SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
            Date dates = new Date();//当前日期
            if (m.matches() && dates.after(sd.parse(date))) {//判断是否满足当前日期或者不超过当前日期
                flag = true;
            }
        } catch (Exception e) {
            flag = false;
        }
        return flag;
    }

}
